package com.example.mountainwalker.service.impl;

import com.example.mountainwalker.entity.TravelAgencyDetail;
import com.example.mountainwalker.mapper.TravelAgencyMapper;
import com.example.mountainwalker.service.TravelAgencyService;
import com.example.mountainwalker.service.impl.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class TravelAgencyServiceImpl implements TravelAgencyService {

    @Autowired
    private TravelAgencyMapper travelAgencyMapper;

    @Override
    public PageResult<TravelAgencyDetail> getTravelAgencyListByCondition(
            String travelAgencyName, String officePhone, String province,
            String city, String auditStatus, Integer pageNum, Integer pageSize) {

        int offset = (pageNum - 1) * pageSize;
        List<TravelAgencyDetail> list = travelAgencyMapper.getTravelAgencyListByCondition(
                travelAgencyName, officePhone, province, city, auditStatus, offset, pageSize);

        int total = travelAgencyMapper.getTravelAgencyCountByCondition(
                travelAgencyName, officePhone, province, city, auditStatus);

        return new PageResult<>(pageNum, pageSize, total, list);
    }

    @Override
    public TravelAgencyDetail getTravelAgencyById(Integer id) {
        return travelAgencyMapper.getTravelAgencyById(id);
    }

    @Transactional
    @Override
    public int deleteTravelAgencyById(Integer id) {
        return travelAgencyMapper.deleteTravelAgencyById(id);
    }

    @Transactional
    @Override
    public int batchDeleteTravelAgency(List<Integer> ids) {
        return travelAgencyMapper.batchDeleteTravelAgency(ids);
    }

    @Transactional
    @Override
    public int updateTravelAgency(TravelAgencyDetail travelAgencyDetail) {
        return travelAgencyMapper.updateTravelAgency(travelAgencyDetail);
    }
}